package controller;

import java.lang.annotation.Annotation;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import pojo.Customer;
import service.CustomerManager;
import service.factory.CustomerManagerFactory;

//@RestController
@Controller
public class CustomerController{
	@Resource(name="customerManagerImpl2")
	private CustomerManager manager;
	
	public void setManager(CustomerManager manager) {
		this.manager = manager;
	}

	@ResponseBody
	@RequestMapping(value="/addform",consumes="application/json")
	public String test1(@RequestBody Customer c){
		System.out.println(c.getName()+"\t"+c.getAge()+"\t"+c.getBirth()+"\t"+c.isSex()+"\t"+c.getSal());
		manager.add(c);
		return "{}";
	}
	
	@ResponseBody
	@RequestMapping(value="/listform")
	public List<Customer> test2(){
		List<Customer> customerlist = manager.getlist();
		return customerlist;
	}
	
	@ResponseBody
	@RequestMapping(value="/delete",consumes="application/json")
	public String test3(@RequestBody Customer c){
		System.out.println(c.getId());
		System.out.println(manager.delete(c.getId()));
		return "{}";
	}
	
	@ResponseBody
	@RequestMapping(value="/update",consumes="application/json")
	public String test4(@RequestBody Customer c){
		System.out.println(c.getId()+"..."+c.getName());
		System.out.println(manager.updateCustomer(c));
		return "{}";
	}
	

}
